package br.com.leopard.util.reflection;

import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;

public class ReflectionUtils {

	public static boolean isClasseAnotada(Class<? extends Annotation> anotation, Class<?> classe) {
		return classe.isAnnotationPresent(anotation);
	}

	public static List<? extends Annotation> getAnnotationFields(Class<? extends Annotation> anotation, Class<?> classe) {
		Field[] fields = classe.getDeclaredFields();

		List<Annotation> anotacoes = new ArrayList<Annotation>();

		for (int i = 0; i < fields.length; i++) {
			Field field = fields[i];

			if (field.isAnnotationPresent(anotation)) {
				anotacoes.add(field.getAnnotation(anotation));
			}
		}

		return anotacoes;
	}

	public static Annotation getAnnotationClass(Class<?> annotationParaBuscar, Class<?> classe) {
		return null;
	}

	public static Class<?> recuperarClasseAtributo(Class<?> classe, String nameAtributo) throws NoSuchMethodException, SecurityException {
		String nomeMetodoRecuperacao = "get" + nameAtributo.substring(0, 1).toUpperCase() + nameAtributo.substring(1, nameAtributo.length());

		return classe.getMethod(nomeMetodoRecuperacao).getReturnType();
	}
}
